package com.lzw.mall.common.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.Random;

public class StringUtil {

	private static final String CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	private static final String NUMSET = "0123456789";

	public static boolean isNotBlank(String str) {
		return str != null && !"".equals(str);
	}
	public static boolean isNotBlank(Integer str) {
		return str != null;
	}
	
	public static String md5(String str) {
		try {
			MessageDigest md=MessageDigest.getInstance("MD5");
			md.update(str.getBytes("UTF-8"));
			return new BigInteger(1,md.digest()).toString(16);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	private String getNext(String ordenno){
		if(ordenno.compareTo("9999")<0){
			ordenno=new DecimalFormat("0000").format(Integer.parseInt(ordenno)+1);
		}else if(ordenno.compareTo("9999")==0){
			ordenno="A000";
		}else{
			String ordennonew="";
			return ordennonew;
		}
		return ordenno;
	}

	public static String generateRandomCode(int length) {
		Random random = new Random();
		StringBuilder sb = new StringBuilder(length);
		for (int i = 0; i < length; i++) {
			int index = random.nextInt(CHARSET.length());
			sb.append(CHARSET.charAt(index));
		}
		return sb.toString();
	}
	public static String generateRandomCode(int length,int num) {
		Random random = new Random();
		StringBuilder sb = new StringBuilder(length);
		for (int i = 0; i < length; i++) {
			int index = random.nextInt(NUMSET.length());
			sb.append(NUMSET.charAt(index));
		}
		return sb.toString();
	}

}
